-- 阳光类
local Object = require("app.mode.Object")
local AniHelper = require("app.utils.AnimateHelper")

local SunShine = {}
SunShine.__index = SunShine
setmetatable(SunShine, Object)

function SunShine:initView()
    self._sprite, self._animate = AniHelper("plants/", "sunshine")
end

function SunShine:exportData()
    local data = Object.exportData(self)
    data.x, data.y = self:getPosition()
    return data
end

-- 执行动画
function SunShine:runAnimate()
    if self._sprite and self._animate then
        self._sprite:runAction(self._animate)

        local x, y = math.random(-3, 3) * 10, math.random(-50, -30)
        local bezier = {cc.p(0, 100), cc.p(x, y), cc.p(x, y + 10)}

        self._sprite:runAction(cc.BezierBy:create(1, bezier))
    end
end

-- 数据
function SunShine:getLife()
    return self._data.life
end

function SunShine:setLife(val)
    self._data.life = val or 16
end

return SunShine
